import { createRouter, createWebHistory } from 'vue-router/auto';
import { setupLayouts } from 'virtual:generated-layouts';
import { NProgress } from '@/utils/nprogress';
import { updateDocumentTitle } from '@/utils/document/documentTitle';
import { useTokenStore } from '@/stores/login/useTokenStore';

const router = createRouter({
  extendRoutes: routes => setupLayouts(routes),
  history: createWebHistory(import.meta.env.BASE_URL),
});

router.beforeEach((to, from) => {
  NProgress.start();

  // const tokenStore = useTokenStore();
  // const { isLoggedIn } = storeToRefs(tokenStore);

  // // 未登录访问非来宾页面
  // if (!isLoggedIn.value && !to.meta?.isGuestPage) {
  //   return { name: 'Auth' };
  // }

  // // 已登录访问来宾页面
  // if (isLoggedIn.value && to.meta?.isGuestPage) {
  //   return { name: 'Home' };
  // }
});

router.beforeResolve((to, from) => {
  updateDocumentTitle(to);
});

router.afterEach((to, from) => {
  NProgress.done();
});

export default router;
